package fifth.cases;

class Check{
    // 验证用户名密码是否正确
    public boolean validate(String name, String password) {
        if(name.equals("Odyssey") && password.equals("123")) {
            return true;
        } else {
            return false;
        }
    }
}

class Operate {
    private String[] info;
    public Operate(String[] info) {
        this.info = info;
    }

    public String login() {
        // 判断参数个数
        this.isExit();
        String username = info[0];
        String pwd = info[1];
         Check check = new Check();
        String calling ;
        if (check.validate(username, pwd)) {
            calling = "hello! " + username;
        } else {
            calling = "your username or pwd is wrong!";
        }
        return calling;
    }

    public void isExit() {
        if (this.info.length < 2) {
            System.out.println("params is less !");
            System.out.println("form: java LoginDemo2.java username pwd.");
            System.exit(1);
        }
    }
}

public class LoginDemo2 {
    public static void main(String[] args) {
        Operate o = new Operate(args);
        System.out.println(o.login());
    }
}
